/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.propertytree;

/**
 *
 * @author amalikov
 */
public class PropertyValue {
	
	public PropertyValue(boolean value) {
		this(value ? 1.0 : 0.0);
	}
	
	public PropertyValue(int value) {
		this((double)value);
	}
	
	public PropertyValue(double value) {
		this.value = value;
		this.strValue = Double.toString(value);
	}
	
	public PropertyValue(String value) {
		this.strValue = value;
		double v = 0;
		try {
			v = Double.parseDouble(value);
		} catch (NumberFormatException e) {
			v = 0;
		} finally {
			this.value = v;
		}
	}
	
	public boolean asBool() {
		return value != 0;
	}
	
	public int asInt() {
		return (int)value;
	}	

	public double asDouble() {
		return value;
	}	
	
	public String asString() {
		return strValue;
	}
	
	@Override
	public String toString() {
		return asString();
	}

	private final String strValue;
	private final double value;
}